package me.youline.dataServer.controller;

import java.util.List;

import javax.servlet.http.HttpServletResponse;

import me.youline.dataServer.service.pubMsg.PubMsgSubjectService;
import me.youline.dataServer.service.support.MsgBuilder;
import me.youline.dataServer.utils.ResponseTypeOutputUtils;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * 公告主题列表控制器
 * @author linhan
 *
 */
@Controller
@RequestMapping("/subject")
public class PubMsgSubjectController {
	
	private Logger logger = LoggerFactory.getLogger(PubMsgSubjectController.class);
	
	@Autowired
	private PubMsgSubjectService subjectService;
	
	/**
	 * 获取主题展示图列表
	 * @param response
	 */
	@RequestMapping("/display/list")
	public void getSubjectDisplayList(HttpServletResponse response){
		try {
			List<String> urls = subjectService.loadSubjectImgUrls();
			response.setStatus(HttpServletResponse.SC_OK);
			ResponseTypeOutputUtils.renderJson(response, MsgBuilder.success().addObj("subjectList", urls).toJSONString());
		} catch (Exception e) {
			logger.error("获取主题展示图列表失败:"+e.getMessage(),e);
			response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
			ResponseTypeOutputUtils.renderJson(response, MsgBuilder.error().errorCode("100001").errorMsg("获取主题展示图列表失败").toJSONString());
		}
	}
}
